import { fetchPost } from '../service/api';

export default {
  namespace: 'global',

  state: {
    env: '0',
    group: [],
  },

  effects: {
    *queryGroup({payload}, {put, call}){
      const response = yield call(fetchPost, "queryGroup.do");
      if(response){
        yield put({
          type: 'saveGroup',
          payload: response.list
        });
      }
    },
  },

  reducers: {
    setEnv(state, action) {
      return {
        ...state,
        env: action.payload,
      }
    },
    saveGroup(state, {payload}){
      return {
        ...state,
        group: payload,
      }
    },
  },

  subscriptions: {
    init({ dispatch, history }){
      dispatch({
        type: 'queryGroup',
      });
    }
  }

}
